#include <cv.h>
#include <highgui.h>

#include "resourceTracker.h"

#include <iostream>

using namespace cv;

VideoGestureTagSequence::VideoGestureTagSequence(CvFileStorage* fs) {
	
	this->fs = fs;
	
	seq = (CvSeq*) cvReadByName(
									   fs,
									   0,
									   "gesture_tag_sequence" //TODO Should be a string const somewhere?
									   );
	
	tagCount = cvReadIntByName(
								  fs,
								  0,
								  "tag_count" //TODO Should be a string const somewhere?
								  );
	
	frameCount =  cvReadIntByName(
								   fs,
								   0,
								   "frame_count" //TODO Should be a string const somewhere?
								   );
	
	currentTag = 0;

}

VideoGestureTagSequence::~VideoGestureTagSequence() {
	cvReleaseFileStorage( &fs );
}

char VideoGestureTagSequence::getNextGestureTag() {
	if ( !(currentTag < tagCount) ) {
		CV_Error( CV_StsError, "No more tags left!"); //throws exception!
	}
	char* tagPtr = CV_GET_SEQ_ELEM( char, seq, currentTag );
	currentTag++;
	return *tagPtr;
}